#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

// 计算数组中元素的个数：
// lengh = sizeof（数组名）/ sizeof（数组类型）;

void func() {
    // 冒泡排序
    char *arr[] = {"840", "kaoyan", "shangan", "highfly", "study", "fighting"};
    int i, j, exchange, len = sizeof(arr) / sizeof(arr[0]); // 获取数组的长度
    char *tmp;
    for (i = 0; i < len-1 ; ++i){
        exchange = 0;
        for (j = len-2; j >= i; --j){
            if (strcmp(arr[j+1], arr[j]) < 0){
                tmp = arr[j+1];
                arr[j+1] = arr[j];
                arr[j] = tmp;
                exchange = 1; // 发生了交换
            }
        }
        if (exchange == 0){
            break;
        }
    }
    for (i = 0; i < len; ++i){
        printf("%s\n", arr[i]);
    }
}

void func2(){
    // 使用指向指针的指针对字符串进行冒泡排序
    char *arr[] = {"840", "kaoyan", "shangan", "highfly", "study", "fighting"};
    char ** pstr = arr;
    int i, j, exchange, len = sizeof(arr) / sizeof(arr[0]); // 获取数组的长度
    char *tmp;
    for (i = 0; i < len-1 ; ++i){
        exchange = 0;
        for (j = len-2; j >= i; --j){
            if (strcmp(arr[j+1], arr[j]) < 0){
                tmp = arr[j+1];
                arr[j+1] = arr[j];
                arr[j] = tmp;
                exchange = 1; // 发生了交换
            }
        }
        if (exchange == 0){
            break;
        }
    }
    for (i = 0; i < len; ++i){
        printf("%s\n", arr[i]);
    }
}

void week(int n){
    switch(n){
        case 1: printf("Monday\n"); break;
        case 2: printf("Tuesday\n"); break;
        case 3: printf("Wednesday\n"); break;
        case 4: printf("Thursday\n"); break;
        case 5: printf("Friday\n"); break;
        case 6: printf("Saturday\n"); break;
        case 7: printf("Sunday\n"); break;
        default: break;
    }

    char * days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", 
                     "Thursday", "Friday", "Saturday", "Sunday"};
    if (n >= 0 && n <= 6){
        printf("%s\n", days[n]);
    }
}

void match(char * str){
    char *arr[] = {"840", "kaoyan", "shangan", "highfly", "study", "fighting"};
    int len = strlen(str);
    int arr_len = sizeof(arr) / sizeof(arr[0]);
    char *start = (char*)malloc(len+1);
    for (int i = 0; i < arr_len; ++i){
        strncpy(start, arr[i], len);
        start[len] = '\0';
        if (strcmp(str, start) == 0){
            printf("%s\n", arr[i]);
            free(start);
            return;
        }
    }
    free(start);
    printf("Not Found\n");
}

void matrix_multiply(){
    int A[2][3] = {1, 2, 3, 4, 5, 6};
    int B[3][2] = {1, 2, 3, 4, 5, 6};
    int res[2][2] = {0};
    // 矩阵相乘
    for (int r = 0; r < 2; ++r){
        for (int c = 0; c < 2; ++c){
            for (int i = 0; i < 3; ++i){
                res[r][c] += A[r][i]*B[i][c];
            }
        }
    }
    // 打印矩阵
    for (int i = 0; i < 2; ++i){
        for (int j = 0; j < 2; ++j){
            printf("%d ", res[i][j]);
        }
        printf("\n");
    }

    // 使用指针数组实现
    int ret[2][2], *p[3];
    p[0] = A[0], p[1] = B[0], p[2] = ret[0]; // 分别指向三个二维数组的起始地址
    for (int r = 0; r < 2; ++r){
        for (int c = 0; c < 2; ++c){
            for (int i = 0; i < 3; ++i){
                res[r][c] += A[r][i]*B[i][c];
            }
        }
    }
    for (int i = 0; i < 2; ++i){
        for (int j = 0; j < 2; ++j){
            printf("%d ", ret[i][j]);
        }
        printf("\n");
    }
}

int main() {
    func();
    int day;
    scanf("%d", &day);
    week(day);

    func2();

    char str[10];
    scanf("%s", str);
    match(str);

    matrix_multiply();

    // char s[] = "hello world";
    // printf("++s = %s\n", ++s); // s是数组名，++s是错误的，不能对常量进行自增
    char *s = "hello world";
    printf("s = %s\n", s);
    printf("*s = %c\n", *s);
    printf("++s = %s\n", ++s); // s指向字符串常量的首地址，++s会使s向后移动一位
    printf("++s = %s\n", ++s);
    
    return 0;
}